package com.hspedu.newData.dmsxl.双指针;
/**
 * @Author: yh
 * @description: 
 * @CreateTime: 2025-05-15 
 * @Version: 1.0
 */

public class LC2337移动片段得到字符串 {

    // todo 模拟还需要加强一下
    public boolean canChange(String start, String target) {
        int i = 0;
        int j = 0;
        int n = start.length();


        while (i<n && j<n){

            while (i<n && start.charAt(i) == '_'){
                i++;
            }

            while (j<n && target.charAt(j) == '_'){
                j++;
            }

            if (i<n&&j<n){
                if (start.charAt(i) != target.charAt(i)){
                    return false;
                }
                char c = start.charAt(i);
                if ((c=='L' && i<j)|| (c=='R' && i>j)){
                    return false;
                }
                i++;
                j++;
            }

        }

        while (i<n){
            if (start.charAt(i) != '_'){
                return false;
            }
            i++;
        }

        while (j<n){
            if (target.charAt(j) != '_'){
                return false;
            }
            j++;
        }
        return true;
    }
}
